const { Pool } = require('pg')

const pool = new Pool({
  user: "postgres",
  host: "localhost",
  database: "hello",
  password: "root",
  port: 5432
})

module.exports = {
  query: (text, params, callback) => {
    const start = Date.now()
    return pool.query(text, params, (err, res) => {
      const duration = Date.now() - start
      if(err){
        callback(err, res);
        console.log(err);
      }else{
        console.log('executed query', { text, duration, rows: res.rowCount })
        callback(err, res)
      }
    })
  }
}

// const MongoClient = require('mongodb').MongoClient;
// // const assert = require('assert');
 
// // Connection URL
//  const url = 'mongodb://localhost:27017';
 
// // // Database Name
//  const dbName = 'hello';
 
// // Use connect method to connect to the server
// // return MongoClient.connect(url, { useNewUrlParser: true }, function(err, client) {
// //   if(err)throw err;
// //   console.log("Connected correctly to server");
// //   const db = client.db(dbName);
// //   // db.collection("users").find({}).toArray(function(err,data){
// //   //   console.log(data)
// //   //   client.close();
// //   // })
// // });

//   MongoClient.connect(url, { useNewUrlParser: true }, function(err, client) {
//     if(err)throw err;
//     console.log("Connected correctly to server");
//     const db = client.db(dbName);
//     db.collection("users").find({user_name:'FinalArno'}).toArray(function(err,data){
//       console.log(data)
//       client.close();
//     })
//   });

      
     


